
public class ExOnThread {

	public static int count = 0;
	public void execute(){
		try {
			
			System.out.println("Hiiiiii");
			String s ="rama";
			System.out.println(s.charAt(5));
			
		}catch(StringIndexOutOfBoundsException so){
			so.printStackTrace();
			count++;
			if(count == 1){
				try {
					Thread.sleep(2000);
					/*System.out.println(Thread.currentThread().getName());
					execute();*/
					//ExOnCurrentThread ex = new ExOnCurrentThread(s)
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}
	
	public static void main(String[] args) {
		
		ExOnThread ex = new ExOnThread();
		ex.execute();
		
	}
	
	private static class ExOnCurrentThread extends Thread{
		String s;
		@SuppressWarnings("unused")
		public ExOnCurrentThread(String s) {
			this.s = s;
		}
		@Override
		public void run() {
			try {
				Class<ExOnThread> clas = (Class<ExOnThread>) Class.forName(s);
				try {
					clas.newInstance().execute();
				} catch (InstantiationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}
}
